package models

import (
	"github.com/astaxie/beego"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"log"
	"time"
)

var (
	Ha666DBConn *xorm.Engine
)

func init() {
	init_ha666db()
}

func init_ha666db() {
	connectionstring := beego.AppConfig.String("ha666db::connectionstring")
	maxidleconns := beego.AppConfig.DefaultInt("ha666db::maxidleconns", 5)
	maxopenconns := beego.AppConfig.DefaultInt("ha666db::maxopenconns", 100)
	db_conn, err := xorm.NewEngine("mysql", connectionstring)
	if err != nil {
		log.Fatalf("【init_ha666db.NewEngine】ex:%s\n", err.Error())
		return
	}
	err = db_conn.Ping()
	if err != nil {
		log.Fatalf("【init_ha666db.Ping】ex:%s\n", err.Error())
		return
	}
	db_conn.TZLocation = time.Local
	db_conn.SetMaxIdleConns(maxidleconns)
	db_conn.SetMaxOpenConns(maxopenconns)
	Ha666DBConn = db_conn
}
